#include "priority_queue.hpp"
#include <iostream>
#include <vector>

void test_min_heap() {
    std::cout << "=== 测试小根堆 (std::less<int>) ===" << std::endl;
    STL::priority_queue<int, STL::vector<int>, std::less<int>> min_heap;
    
    // 插入多个数据
    std::vector<int> test_data = {3, 1, 6, 8, 2, 4, 9, 5, 7};
    
    std::cout << "插入顺序: ";
    for (int num : test_data) {
        std::cout << num << " ";
        min_heap.push(num);
    }
    std::cout << std::endl;
    
    std::cout << "堆化后的结构: ";
    min_heap.print();
    std::cout << "堆大小: " << min_heap.size() << std::endl;
    
    std::cout << "逐个pop的顺序: ";
    while (!min_heap.empty()) {
        std::cout << min_heap.top() << " ";
        min_heap.pop();
    }
    std::cout << std::endl << std::endl;
}

void test_max_heap() {
    std::cout << "=== 测试大根堆 (std::greater<int>) ===" << std::endl;
    STL::priority_queue<int, STL::vector<int>, std::greater<int>> max_heap;
    
    // 插入多个数据
    std::vector<int> test_data = {3, 1, 6, 8, 2, 4, 9, 5, 7};
    
    std::cout << "插入顺序: ";
    for (int num : test_data) {
        std::cout << num << " ";
        max_heap.push(num);
    }
    std::cout << std::endl;
    
    std::cout << "堆化后的结构: ";
    max_heap.print();
    std::cout << "堆大小: " << max_heap.size() << std::endl;
    
    std::cout << "逐个pop的顺序: ";
    while (!max_heap.empty()) {
        std::cout << max_heap.top() << " ";
        max_heap.pop();
    }
    std::cout << std::endl << std::endl;
}

void test_edge_cases() {
    std::cout << "=== 测试边界情况 ===" << std::endl;
    
    // 测试空堆
    STL::priority_queue<int, STL::vector<int>, std::less<int>> heap;
    std::cout << "空堆是否为空: " << (heap.empty() ? "是" : "否") << std::endl;
    
    // 测试单个元素
    heap.push(42);
    std::cout << "插入单个元素后: ";
    heap.print();
    std::cout << "顶部元素: " << heap.top() << std::endl;
    
    // 测试两个元素
    heap.push(10);
    std::cout << "插入第二个元素后: ";
    heap.print();
    
    // 测试重复元素
    heap.push(42);
    heap.push(42);
    heap.push(10);
    std::cout << "插入重复元素后: ";
    heap.print();
    
    std::cout << "逐个pop: ";
    while (!heap.empty()) {
        std::cout << heap.top() << " ";
        heap.pop();
    }
    std::cout << std::endl << std::endl;
}

void test_large_heap() {
    std::cout << "=== 测试大量数据 ===" << std::endl;
    STL::priority_queue<int, STL::vector<int>, std::less<int>> heap;
    
    // 插入20个数据
    for (int i = 20; i >= 1; i--) {
        heap.push(i);
    }
    
    std::cout << "插入20-1后堆结构: ";
    heap.print();
    
    std::cout << "有序输出: ";
    while (!heap.empty()) {
        std::cout << heap.top() << " ";
        heap.pop();
    }
    std::cout << std::endl << std::endl;
}

int main() {
    // 测试小根堆
    test_min_heap();
    
    // 测试大根堆  
    test_max_heap();
    
    // 测试边界情况
    test_edge_cases();
    
    // 测试大量数据
    test_large_heap();
    
    return 0;
}